package com.example.wordroom

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

@Database(entities = arrayOf(Word::class), version = 1, exportSchema = false)
abstract class WordDataBase: RoomDatabase() {

    abstract fun wordDao():WordDao

    companion object{

        var instance: WordDataBase? = null

        fun getInstance(context: Context):WordDataBase{
            instance?.let {
                return instance as WordDataBase
            }
            instance = Room.databaseBuilder(
                context,
                WordDataBase::class.java,
                "db_word")
                .fallbackToDestructiveMigration()
                .build()
            return instance as WordDataBase
        }
    }

}